﻿Imports System.Windows.Forms
Imports System.Drawing

Namespace formularios

    Public Class FormUtilerias

        Public Shared Sub centrarFormularioHijo(ByRef formularioPadre As Form, ByRef formularioHijo As Form)
            formularioHijo.StartPosition = FormStartPosition.CenterScreen
        End Sub

        Public Shared Sub centrarFormularioHijo2(ByRef formularioPadre As Form, ByRef formularioHijo As Form)
            Dim x, y As Integer

            x = CInt(formularioPadre.ClientRectangle.Width / 2 - formularioHijo.Width / 2)
            y = CInt(formularioPadre.ClientRectangle.Height / 2 - formularioHijo.Height / 2)

            formularioHijo.StartPosition = FormStartPosition.Manual

            formularioHijo.Location = New Point(x, y)
        End Sub

        Public Shared Sub asignarToolTip(ByRef tooltip As ToolTip, ByRef control As Control, ByVal texto As String)
            tooltip.SetToolTip(control, texto)
        End Sub

        Public Shared Sub deshabilitarBotones(ByVal ParamArray botones() As Button)
            Dim boton As Button = Nothing
            For Each boton In botones
                boton.Enabled = False
            Next
        End Sub

        Public Shared Sub deshabilitarControles(ByVal ParamArray controles() As Control)
            Dim ctr As Control = Nothing
            For Each ctr In controles
                ctr.Enabled = False
            Next
        End Sub

        Public Shared Sub enableTextBox(ByRef f As Form)
            For Each txt As TextBox In ListaDeControles(New List(Of Control), f, GetType(TextBox))
                txt.Enabled = True
            Next
        End Sub

        Public Shared Sub disableTextBox(ByRef f As Form)
            For Each txt As TextBox In ListaDeControles(New List(Of Control), f, GetType(TextBox))
                txt.Enabled = False
            Next
        End Sub

        Public Shared Sub cleanTextBox(ByRef f As Form)
            For Each txt As TextBox In ListaDeControles(New List(Of Control), f, GetType(TextBox))
                txt.Text = vbNullString
            Next
        End Sub

        Public Shared Function ListaDeControles(ByVal list As List(Of Control), ByVal parent As Control, ByVal ctrlType As System.Type) As List(Of Control)
            If parent Is Nothing Then Return list
            If parent.GetType Is ctrlType Then
                list.Add(parent)
            End If
            For Each child As Control In parent.Controls
                ListaDeControles(list, child, ctrlType)
            Next
            Return list
        End Function

        'Public Shared Function estaIniciado(ByRef f As Form, ByRef tipo As ) As Boolean
        '    For Each child In f.MdiChildren
        '        If TypeOf child Is  Then
        '            child.BringToFront()
        '            Return True
        '        End If
        '        Return False
        '    Next
        'End Function


    End Class
End Namespace

